package HomeWork;

import java.io.*;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeSet;
import java.util.function.Consumer;

public class Demo07 {
    public static void main(String[] args) throws Exception {
        TreeSet<Hero> heroSet=new TreeSet<>(new Comparator<Hero>() {
            @Override
            public int compare(Hero o1, Hero o2) {
                return Double.compare(o2.getScore(),o1.getScore());
            }
        });
        BufferedReader br=new BufferedReader(new FileReader("D:\\黑马线下\\68期\\Java进阶\\课后作业\\day10\\hero.txt", Charset.forName("GBK")));
        String line;
        int i=1;
        while((line=br.readLine())!=null){
            String[] split = line.split("(,+)|(\\s)");
            if(i>=2){
                heroSet.add(new Hero(split[0],split[1], split[2],split[3],Integer.parseInt(split[1])*0.5+Integer.parseInt(split[2])*0.2+Integer.parseInt(split[3])*0.3));
            }
           i++;
        }

        heroSet.forEach(new Consumer<Hero>() {
            @Override
            public void accept(Hero hero) {
                System.out.println(hero);
            }
        });

        BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\黑马线下\\68期\\Java进阶\\课后作业\\day10\\hero1.txt"));
        bw.write("姓名 "+"生存 "+"攻击 "+"效果 "+"新手适应分 ");
        bw.newLine();
        for(Hero h:heroSet){
            bw.write(h.getName()+","+h.getLive()+","+h.getHurt()+","+h.getEffect()+","+h.getScore());
            bw.newLine();
        }
        bw.close();
        br.close();


    }
}

class Hero{
    private String name;
    private String live;
    private String hurt;
    private String effect;

    private Double score;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLive() {
        return live;
    }

    public void setLive(String live) {
        this.live = live;
    }

    public String getHurt() {
        return hurt;
    }

    public void setHurt(String hurt) {
        this.hurt = hurt;
    }

    public String getEffect() {
        return effect;
    }

    public void setEffect(String effect) {
        this.effect = effect;
    }

    public Double getScore() {
        return score;
    }

    public void setScore(Double score) {
        this.score = score;
    }

    public Hero(String name, String live, String hurt, String effect, Double score) {
        this.name = name;
        this.live = live;
        this.hurt = hurt;
        this.effect = effect;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Hero{" +
                "name='" + name + '\'' +
                ", live='" + live + '\'' +
                ", hurt='" + hurt + '\'' +
                ", effect='" + effect + '\'' +
                ", score=" + score +
                '}';
    }
}
